<%@ page import="com.oval.util.JspHelper" %>
<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="com.oval.util.*" %>
<%@ page import= "org.apache.log4j.*"%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/chinese/csscontent.css" type="text/css">

<%  
    Vector submitV = new Vector();
    int maxlth = 0;
    
    Vector vvv = new Vector();
    Enumeration enum = Category.getCurrentCategories();
    while(enum.hasMoreElements())  // get the max capacity of the container
    {
      String tmp = ((Category)enum.nextElement()).getName();
      StringTokenizer st = new StringTokenizer(tmp,".");
      int tmplth = st.countTokens();
      maxlth = Math.max(maxlth,tmplth);
    }
    Vector[] vv = new Vector[maxlth+1];  // init the container
    for(int l = 0; l<vv.length; l++)
    {
      vv[l] = new Vector();
    }
    
    int id = 1;
    Enumeration enum2 = Category.getCurrentCategories();
    while(enum2.hasMoreElements())  // category the names according to the layer
    {
      Category a_cat = (Category)enum2.nextElement();
      String tmp = a_cat.getName();
      String fathername = "";
      Level level = a_cat.getLevel();
      Level levelFromHierarchy = a_cat.getEffectiveLevel();
      int level_int = levelFromHierarchy.toInt()/10000;
      StringTokenizer st = new StringTokenizer(tmp,".");
      int tmplth = st.countTokens(); 
      HashMap catinfo = new HashMap();
      catinfo.put("name",tmp);
      catinfo.put("fathername",fathername);
      catinfo.put("level",level);
      catinfo.put("levelFromHierarchy",levelFromHierarchy);
      catinfo.put("level_int",new Integer(level_int));
      catinfo.put("length",new Integer(tmplth));
      catinfo.put("id",new Integer(id));
      catinfo.put("grade",new Integer(1));
      vv[tmplth].add(catinfo);
      id++;
    }
    
    for(int j=1;j<vv.length;j++)  // get every layer order by asc 
    {
      if(vv[j]!=null && vv[j].size()!=0)  
      {
        for(int m = 0 ;m < vv[j].size() ;m++)  // find every item of the layer 
        {
          boolean flag = false;
          HashMap a_catinfo = (HashMap)vv[j].get(m);
          String a_name = (String)a_catinfo.get("name");  // get the current name of the item
          for(int n = j-1 ;n >=0&&!flag;n--)  // find the prelayers order by desc
          {
            for(int o = 0; o< vv[n].size()&&!flag ;o++)  
            {
              HashMap tmp_catinfo = (HashMap)vv[n].get(o);
              String tmp_name = (String)tmp_catinfo.get("name"); // the item in the prelayer
              int tmp_grade = ((Integer)tmp_catinfo.get("grade")).intValue();
              Integer tmp_id = (Integer)tmp_catinfo.get("id");
              if((a_name.trim()).startsWith(tmp_name.trim()))
              {
                a_catinfo.put("fathername",tmp_name);
                a_catinfo.put("fatherid",tmp_id);
                int m_grade = tmp_grade+1;
                a_catinfo.put("grade",new Integer(m_grade));
                vvv.add(vvv.indexOf(tmp_catinfo)+1,a_catinfo); //add the name of the layer just after one of the prelayer 
                flag = true;
              } 
            }
          }
          if(!flag)  vvv.add(a_catinfo); // add the name of the layer in the end of the container
        }
      } 
    }
    OvalTree initTree = new OvalTree(vvv,"id","fatherid","grade");
    initTree.setRecursiveLimit(2000);
    Vector logTree = (Vector)initTree.getTreeVector(new Integer(-1000),1);
    
%>


<SCRIPT language=JavaScript1.2 src="../../css/menu.js"></SCRIPT>

<SCRIPT language=JavaScript>
parent.rightFrame.location.href = "Blank.jsp";
function page_view(name)
{
  if(name == null || name == "")
  {
    return;
  }
  var viewlog = "SetCategoryList.jsp?logname=" + name;
  parent.rightFrame.location.href = viewlog;
}
</SCRIPT>

</head>
<body bgcolor="#FFFFFF" text="#000000" >
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  <form name="logTreeform" method="post" action="../../Dispatcher">
       <input type="hidden" name="pagename" value="SetCategory">
       <input type="hidden" name="actionname">
  <tr> 
    <td valign="top"> 
      <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#EEEEEE">
        <tr height="30"  align="center"> 
          <td colspan="-1" class="td_title_bg"><img src="../../images/en/quote.gif" width="16" height="11"> <B>Categories List</B></td>
        </tr>
        <tr> 
          <td class="spe-td">                         
		       <div id=div2 style="OVERFLOW: scroll; WIDTH: 234px; HEIGHT: 465px">
             <%
             if(logTree.size() != 0)
             {
               int nTreeLevel = 0;
               int nLevelDif = 0;
               int nTopLevel = 0;
               int nEndLevel = 0;
               String strIMG = "TreeAdd.gif";
               for(int i = 0;i < logTree.size();i++)
               {
                 HashMap temp = (HashMap)logTree.elementAt(i);
                 int nNext = ((Integer)temp.get("next")).intValue();
                 String strLevelCode = (String)temp.get("levelcode");       
                 nTreeLevel = ((Integer)temp.get("grade")).intValue()+ nLevelDif;
                 if(((Boolean)temp.get("ismin")).booleanValue())
                 {
                   strIMG = "TreeSub.gif";
                 }
                 else
                 {
                   strIMG = "TreeAdd.gif";
                 }
                 for(int j = 0;j <= -nNext;j++)
                 {
                   if(i != 0)
                   {
                   %>
                    </div>                   
                   </td>
                  </tr>               
                 </table>
                 <%    
                   }
                 }
                 if(((Boolean)temp.get("ismax")).booleanValue())
                 {
                   nTopLevel = ((Integer)temp.get("grade")).intValue();
                   nTreeLevel = 1;
                   nLevelDif = ((Integer)temp.get("grade")).intValue() - 1;
                %> 
                <table cellspacing="0" width="100%">     
                 <tr height="20"> 
                  <td class="TreeClass1">&nbsp;&nbsp;<a href="#" <%if(!((Boolean)temp.get("ismin")).booleanValue()){%>onClick="expandIt(logTreeform,'KB<%=JspHelper.filterNull( strLevelCode )%>','../../images/en/'); return false"<%}%>><img name="KB<%=JspHelper.filterNull( strLevelCode )%>wj" src="../../images/en/<%=JspHelper.filterNull( strIMG )%>" height="11" border="0" ></a>&nbsp;&nbsp;<a href="javascript:page_view('<%=JspHelper.filterNull( temp.get("name") )%>')"><%=JspHelper.filterNull( temp.get("name"))%></a> 
                   <div class=child<%=JspHelper.filterNull( strLevelCode )%> id=KB<%=JspHelper.filterNull( strLevelCode )%>Child> 
                <%   
                 } 
                 if(!((Boolean)temp.get("ismax")).booleanValue() && !((Boolean)temp.get("ismin")).booleanValue())
                 {
                %>
                <table cellspacing="0" width="100%">     
                 <tr height="20"> 
                  <td class="TreeClass<%=JspHelper.filterNull( nTreeLevel )%>">&nbsp;&nbsp;<a href="#" onClick="expandIt(logTreeform,'KB<%=JspHelper.filterNull( strLevelCode )%>','../../images/en/'); return false"><img src="../../images/en/<%=JspHelper.filterNull( strIMG )%>" width="11" height="11" name="KB<%=JspHelper.filterNull( strLevelCode )%>wj" border="0"></a>&nbsp;&nbsp;<a href="javascript:page_view('<%=JspHelper.filterNull( temp.get("name") )%>')"><%=JspHelper.filterNull( temp.get("name"))%></a>
                  <div class=child<%=JspHelper.filterNull( strLevelCode )%> id=KB<%=JspHelper.filterNull( strLevelCode )%>Child> 
               <%
                 }
                 if(!((Boolean)temp.get("ismax")).booleanValue() && ((Boolean)temp.get("ismin")).booleanValue())
                 {
               %>
                <table cellspacing="0" width="100%">     
                 <tr height="20"> 
                  <td class="TreeClass<%=JspHelper.filterNull( nTreeLevel )%>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#"><img src="../../images/en/<%=JspHelper.filterNull( strIMG )%>" width="11" height="11" name="KB<%=JspHelper.filterNull( strLevelCode )%>wj" border="0"></a>&nbsp;&nbsp;<a href="javascript:page_view('<%=JspHelper.filterNull( temp.get("name") )%>')"><%=JspHelper.filterNull( temp.get("name"))%></a>
                   <div>  
               <%
                 }
                 nEndLevel = ((Integer)temp.get("grade")).intValue();
               }     
               //close the tag
               for(int h = 0; h <= nEndLevel - nTopLevel;h++)
               {
               %>
                        </div>     
                       </td>
                      </tr>    
                     </table>              
               <%  
               }
             }          
             %>
                </div>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </form> 
</table>
</body>
<SCRIPT language=JavaScript1.2>initIt(logTreeform,'../../images/en/');</SCRIPT>
</html>

